/*
 *  Attacks.cpp
 *  
 *	Version 1.0
 *  Created by Nicholas Blecha on 9/25/10.
 *  Copyright 2010 Michigan Technological University. All rights reserved.
 *
 */

#include "Attacks.h"
#include "Fighter.h"


std::string Attack::getDesc() {
	return description;
}

std::string Attack::getName() {
	return name;
}

Attack::Attack(std::string desc, std::string newName) {
	description = desc;
	name = newName;
}

NormalAttack::NormalAttack(std::string desc, std::string name) : Attack(desc, name) {
}

WideAttack::WideAttack(std::string desc, std::string name) : Attack(desc, name) {
}

SpecialAttack::SpecialAttack(std::string desc, std::string name) : Attack(desc, name) {
}

int SpecialAttack::getMaxUses() {
	return maxUses;
}

int SpecialAttack::getUses() {
	return numberOfUses;
}

int SpecialAttack::addUses(int addedUses) {
	numberOfUses += addedUses;
	if (numberOfUses > maxUses) {
		numberOfUses = maxUses;
	}
	return numberOfUses;
}

StandardNormalAttack::StandardNormalAttack(Fighter* own) : NormalAttack("Normal Attack", "Fires a single beam at full power") {
	owner = own;
}

bool StandardNormalAttack::fire() {
	Beam* firedBeam = owner->getNewBeam();
	if (firedBeam!=NULL) {
		//firedBeam->setImage(owner->getDefaultImagePath());
		SDL_Rect* fighterRect = owner -> getRect();
		int xCenter = fighterRect->x + fighterRect->w/2;
		int yCenter = fighterRect->y + fighterRect->h/2;
		int x = (int)(xCenter - 64 * cos(owner->getAngle()+M_PI/2));
		int y = (int)(yCenter - 64 * sin(owner->getAngle()+M_PI/2));
		x -= firedBeam->getRect()->w/2;
		y -= firedBeam->getRect()->h/2;
		firedBeam->initialize(owner->getPower(), 25, owner->getAngle(), x, y);
		firedBeam->setActive(true);
		return true;
		}
	return false;
	}

FastNormalAttack::FastNormalAttack(Fighter* own) : NormalAttack("Fast Normal Attack","Fire a single beam at 80 percent power that is slightly faster") {
	owner = own;
}
bool FastNormalAttack::fire() {
	Beam* firedBeam = owner->getNewBeam();
	if (firedBeam!=NULL) {
		//firedBeam->setImage(owner->getDefaultImagePath());
		SDL_Rect* fighterRect = owner -> getRect();
		int xCenter = fighterRect->x + fighterRect->w/2;
		int yCenter = fighterRect->y + fighterRect->h/2;
		int x = (int)(xCenter - 64 * cos(owner->getAngle()+M_PI/2));
		int y = (int)(yCenter - 64 * sin(owner->getAngle()+M_PI/2));
		x -= firedBeam->getRect()->w/2;
		y -= firedBeam->getRect()->h/2;
		firedBeam->initialize(owner->getPower()*4/5, 35, owner->getAngle(), x, y);
		firedBeam->setActive(true);
		return true;
	}
	return false;
}

StandardWideAttack::StandardWideAttack(Fighter* own) : WideAttack("Wide Attack", "Fire two beams at half power") {
	owner = own;
}

bool StandardWideAttack::fire() {
	Beam* firedBeam1 = owner->getNewBeam();
	if (firedBeam1!=NULL) {
		firedBeam1->setActive(true);
		Beam* firedBeam2 = owner->getNewBeam();
		if (firedBeam2!=NULL) {
			//firedBeam1->setImage(owner->getDefaultImagePath());
			//firedBeam2->setImage(owner->getDefaultImagePath());
			SDL_Rect* fighterRect = owner -> getRect();
			int xCenter = fighterRect->x + fighterRect->w/2;
			int yCenter = fighterRect->y + fighterRect->h/2;
			int x1 = (int)(xCenter - 32 * cos(owner->getAngle()+3*M_PI/4));
			int y1 = (int)(yCenter - 32 * sin(owner->getAngle()+3*M_PI/4));
			int	x2 = (int)(xCenter - 32 * cos(owner->getAngle()+M_PI/4));
			int y2 = (int)(yCenter - 32 * sin(owner->getAngle()+M_PI/4));
			x1 -= firedBeam1->getRect()->w/2;
			y1 -= firedBeam1->getRect()->h/2;
			x2 -= firedBeam2->getRect()->w/2;
			y2 -= firedBeam2->getRect()->h/2;
			firedBeam1->initialize(owner->getPower(), 25, owner->getAngle(), x1, y1);
			firedBeam2->initialize(owner->getPower(), 25, owner->getAngle(), x2, y2);
			firedBeam2->setActive(true);
			return true;
		} else {
			firedBeam1->setActive(false);
		}

	}
	return false;
	
}

MissileAttack::MissileAttack(Fighter* own) : SpecialAttack("Missile Attack", "Fire up to five missile damaging three times your power") {
	owner = own;
	maxUses=5;
	numberOfUses = 5;
}

bool MissileAttack::fire() {
	Beam* firedBeam = owner->getNewBeam();
	if (firedBeam!=NULL) {
		//firedBeam->setImage("Images//laser2.png");
		SDL_Rect* fighterRect = owner -> getRect();
		int xCenter = fighterRect->x + fighterRect->w/2;
		int yCenter = fighterRect->y + fighterRect->h/2;
		int x = (int)(xCenter - 64 * cos(owner->getAngle()+M_PI/2));
		int y = (int)(yCenter - 64 * sin(owner->getAngle()+M_PI/2));
		x -= firedBeam->getRect()->w/2;
		y -= firedBeam->getRect()->h/2;
		firedBeam->initialize(owner->getPower()*3, 25, owner->getAngle(), x, y);
		firedBeam->setActive(true);
		return true;
	}
	return false;
}

HPDrainAttack::HPDrainAttack(Fighter* own) : SpecialAttack("HP Drain Attack", "An attack that does damage equal to twice your power but drains 10 HP every time you use it.") {
	owner = own;
}

bool HPDrainAttack::fire() {
	Beam* firedBeam = owner->getNewBeam();
	if (firedBeam!=NULL && owner->getHP() > 10) {
		//firedBeam->setImage(owner->getDefaultImagePath());
		SDL_Rect* fighterRect = owner -> getRect();
		int xCenter = fighterRect->x + fighterRect->w/2;
		int yCenter = fighterRect->y + fighterRect->h/2;
		int x = (int)(xCenter - 64 * cos(owner->getAngle()+M_PI/2));
		int y = (int)(yCenter - 64 * sin(owner->getAngle()+M_PI/2));
		x -= firedBeam->getRect()->w/2;
		y -= firedBeam->getRect()->h/2;
		firedBeam->initialize(owner->getPower(), 25, owner->getAngle(), x, y);
		firedBeam->setActive(true);
		owner->dmg(10);
		return true;
	}
	return false;
}
